package cn.donting.jme.project.gradle;


import cn.donting.jme.EditorContent;
import cn.donting.jme.project.Project;
import cn.donting.jme.texture.TextureLoader;
import com.jme3.asset.AssetManager;
import com.jme3.asset.DesktopAssetManager;
import com.jme3.asset.plugins.FileLocator;
import com.jme3.system.JmeSystem;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;

public class GradleProject implements Project {
    private final File projectRootDir;
    private ProjectClassloader classLoader;

    public GradleProject(File projectRootDir) {
        this.projectRootDir = projectRootDir;
        classLoader = new ProjectClassloader();
        try {
            classLoader.addURL(getSrcResourcesDir().toURI().toURL());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public File getProjectDir() {
        return projectRootDir;
    }

    @Override
    public File getSrcJavaDir() {
        return new File(projectRootDir, "src/main/java");
    }

    @Override
    public File getSrcMainDir() {
        return new File(projectRootDir, "src/main");
    }

    @Override
    public File getSrcDir() {
        return new File(projectRootDir, "src");
    }

    @Override
    public File getSrcResourcesDir() {
        return new File(projectRootDir, "src/main/resources");
    }

    @Override
    public void build() {
        throw new UnsupportedOperationException("build");
    }

    @Override
    public void reBuild() {
        throw new UnsupportedOperationException("reBuild");
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("clear");
    }

    @Override
    public void compile() {
        throw new UnsupportedOperationException("compile");
    }

    @Override
    public void packageDesktop() {
        throw new UnsupportedOperationException("packageDesktop");
    }

    @Override
    public ClassLoader getClassLoader() {
        return classLoader;
    }



    private static class ProjectClassloader extends URLClassLoader {

        public ProjectClassloader() {
            super(new URL[]{});
        }

        @Override
        public void addURL(URL url) {
            super.addURL(url);
        }
    }
}
